package com.asset.dispoal.configurationBatch.service.commom;

import com.asset.dispoal.configurationBatch.domain.db.entity.ConfigurationBatch;
import com.asset.dispoal.configurationBatch.domain.db.mapper.ConfigurationBatchMapper;
import com.asset.dispoal.configurationBatch.dto.ConfigurationBatchRequest;
import com.asset.dispoal.configurationBatch.service.converter.ConfigurationBatchConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/3/25$
 */
@Component
public class ConfigurationBatchInsertCommand implements BaseCommand<ConfigurationBatchRequest, Result> {

    @Autowired
    ConfigurationBatchMapper configurationBatchMapper;

    @Override
    @Transactional
    public Result execute(ConfigurationBatchRequest request) {
        ConfigurationBatch configurationBatch = ConfigurationBatchConverter.INSTANCE.reqToDo(request);
        configurationBatchMapper.delete(request.getAssetInstBatchId());
        configurationBatchMapper.insert(configurationBatch);
        return Result.ok();
    }
}
